<!--
 * @Author: chenhuanhuan 2925102113@qq.com
 * @Date: 2024-08-26 14:57:33
 * @LastEditors: chenhuanhuan 2925102113@qq.com
 * @LastEditTime: 2024-09-24 11:15:57
 * @FilePath: \orderApp\packageOne\pages\personalInfo\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<route lang="json5" type="page">
{
  layout: "default",
  style: {
    navigationStyle: "custom",
    navigationBarTextStyle: "black",
  },
}
</route>

<template>
  <view class="">
    <cu-navbar title="我的评议"></cu-navbar>

    <view class="wrap">
      <view v-if="adviceList.length">
        <reviewComment
          v-for="(item, index) in adviceList"
          :itemData="item"
          :itemIdx="index"
          @unLike="changelike"
          :key="index"
          :showDel="true"
          :showLike="false"
             :isAny="false"
        >
        </reviewComment>
        <uv-load-more
              line
              :status="loadMore.status"
              :loading-text="loadMore.loadingText"
              :loadmore-text="loadMore.loadmoreText"
              :nomore-text="loadMore.nomoreText"
              @loadmore="loadHandler"
            />
      </view>
      <view v-else>
        <cu-empty></cu-empty>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
//
import { getMyAdvice, deleteMyAdvice } from "@/service/business/login";

import reviewComment from "@/pages/components/reviewComment.vue";
import { useUserStore } from "@/store";
const { user } = useUserStore().userInfo;

const changelike = (index) => {
  let { adviceId } = adviceList.value[index];
  uni.showModal({
    title: "提示",
    content: "您确定删除该评议吗？",
    success:  (resolve) => {
      console.log(resolve,'iii')
      if(resolve.confirm){
        deleteMyAdvice({ adviceId }).then(res => {
          if(res.retCode == 2000){
            adviceList.value.splice(index,1)
            uni.showToast({
              title: '删除成功',
              icon: 'none',
            });
          }
        });
      }     
    },
  });
};

// 加载状态数据
const loadMore = ref({
  status: "loading",
  loadingText: "努力加载中",
  loadmoreText: "上拉或点击加载更多",
  nomoreText: "到底啦",
});

// 分页信息
const pageInfo = ref({
  size: 10,
  current: 1,
  total: null,
});
// 手动加载更多
const loadHandler = () => {
  loadMoreFn();
};

// 触底加载更多
onReachBottom(() => {
  loadMoreFn();
});

const loadMoreFn = () => {
  if (pageInfo.value.current >= Math.ceil(pageInfo.value.total / pageInfo.value.size)) {
    loadMore.value.status = "nomore";
    return false;
  }
  pageInfo.value.current++;
  reqMyAdvice();
};

const adviceList = ref([]);
const reqMyAdvice = () => {
  uni.showLoading({
    title: "加载中",
    mask: true,
  });
  loadMore.value.status = "loading";
  let params = {
    size: pageInfo.value.size,
    current: pageInfo.value.current,
    userId: user.userId,
  };
  getMyAdvice(params).then((res) => {
    if (res.retCode == 2000) {
      uni.hideLoading();
      adviceList.value.push(...res.data);
      pageInfo.value.total = res.total;
      if (pageInfo.value.current < Math.ceil(res.total / pageInfo.value.size)) {
        loadMore.value.status = "loadmore";
      } else {
        loadMore.value.status = "nomore";
      }
    }
  });
};

onMounted(() => {
  reqMyAdvice();
});
</script>

<style lang="scss" scoped>
//
.wrap{
  padding: 0 24rpx;
}
</style>
